
import _axios, { get, put, _delete } from '@/lin/plugin/axios'

// 我们通过 class 这样的语法糖使模型这个概念更加具象化，其优点：耦合性低、可维护性。
class Receive {
  // 类中的方法可以代表一个用户行为
  async createReceive(data) {
    return _axios({
      method: 'post',
      url: 'v1/receive',
      data,
    })
  }

  // 在这里通过 async await 语法糖让代码同步执行
  // 1. await 一定要搭配 async 来使用
  // 2. await 后面跟的是一个 Promise 对象
  async getReceive(id) {
    const res = await get(`v1/receive/${id}`)
    return res
  }

  async search({ status, page, count }) {
    const res = await get('v1/receive/search', {
      count,
      page,
      status
    })
    return res
  }

  async getCountByStatus() {
    const res = await get(`v1/receive/count`)
    return res
  }

  async editReceive(id, info) {
    const res = await put(`v1/receive/${id}`, info)
    return res
  }

  async deleteReceive(id) {
    const res = await _delete(`v1/receive/${id}`)
    return res
  }

  async getReceives(page = 0,count = 10) {
    const res = await get('v1/receive/page',{page,count})
    return res
  }

  async deleteSuccess() {
    const res = await _delete('v1/receive/delete/suc')
    return res
  }

  async deleteInvalid() {
    const res = await _delete('v1/receive/delete/invalid')
    return res
  }
}
export default new Receive()